<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <input type="file" multiple>
  <div class="box">
  </div>
  <script type="text/javascript">
  var input=document.querySelector("input");
  var div=document.querySelector(".box");
  input.addEventListener("change",function (event){
    var formData=new FormData();
    for(let file of event.target.files){
      formData.append("myfiles",file);
    }
    upload(formData);
  });

function upload(formData){
  var  xml=new XMLHttpRequest();
  xml.open("POST","/lesson15-2/up");
  xml.responseType="json";
  xml.onreadystatechange=function (){
    if(xml.status === 200 && xml.readyState === 4)
    {console.log(xml.response);
      xml.response.forEach(file=>{
            addImg(file.filename);
      })
    }
  }
  xml.send(formData);}

  function addImg(url){
    var img=new Image();
    img.src="lesson15-2/img/"+url;
    div.appendChild(img);
  }
  </script>
</body>
</html>
